<template>
    <div class="yuan-container container">
        <a-card  title="颗粒提取物库存表">
            <div class="filter-list" style="display: flex;justify-content: space-between">
                <div>
                    <a-select style="width: 200px;float: left" @change="getTableData" placeholder="选择类型">
                        <a-select-option value="提取物">提取物</a-select-option>
                        <a-select-option value="配方颗粒(颗粒)">配方颗粒(颗粒)</a-select-option>
                    </a-select>
                </div>
                <div>
                    <a-button style="margin-bottom:10px;z-index: 10;margin-right: 10px" type="primary" @click="add">新增</a-button>
                    <a-button type="primary" @click="downloadTemplate">下载导入模板</a-button>
                    <a-upload name="file" :multiple="false" :before-upload="beforeUpload" :showUploadList="false">
                        <a-button type="primary" style="margin-left: 5px;margin-right: 0">导入</a-button>
                    </a-upload>
                </div>
            </div>
            <a-table
                :scroll="{ x: 1500 }"
                :loading="tableOption.loading"
                bordered
                :rowKey="item=>item.id"
                :data-source="tableOption.dataSource"
                :columns="tableOption.tableColumns"
                :pagination="tableOption.pagination">
            </a-table>
        </a-card>
        <!-- 弹窗表单 -->
        <addOrEdit :formData="formData" :visible="formShow" :editId="formEditId" @closeModal="formClose"></addOrEdit>
    </div>
</template>
<script lang="ts">
import {Vue, Component} from 'vue-property-decorator';
import AddOrEdit from "@/views/reportMgt/grainInventory/components/addOrEdit.vue";
import {h} from "vue";
import nextApi from "@/api/nextApi";
import {downLoadFile} from "@/utils";
import locale from "ant-design-vue/lib/date-picker/locale/zh_CN";
@Component({
    components: {AddOrEdit}
})
export default class  extends Vue {
    //表格配置
    tableOption: any = {
        loading:false,
        tableColumns: [
            {
                title: "粉批号及信息",
                align: "center",
                children:[
                    {
                        title: "序号",
                        dataIndex: "index",
                        key: "index",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => index + 1
                    },
                    {
                        title: "品名",
                        dataIndex: "materialName",
                        key: "materialName",
                        align: "center",
                    },
                    {
                        title: "标准类型(企/国/省标)",
                        dataIndex: "categoryCode",
                        key: "categoryCode",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-select",
                                {
                                    style:{width:"100%"},
                                    props:{
                                        value: record.categoryCode,
                                        options:[
                                            {
                                                value:"国标",
                                                label:"国标"
                                            },
                                            {
                                                value:"省标",
                                                label:"省标"
                                            },
                                            {
                                                value:"省标-北京",
                                                label:"省标-北京"
                                            },
                                            {
                                                value:"省标-上海",
                                                label:"省标-上海"
                                            }
                                        ]
                                    },
                                    on:{
                                        change: (data: any) => {
                                            record.categoryCode = data
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "粉批号",
                        dataIndex: "batch",
                        key: "batch",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input",
                                {
                                    style:{width:"100%"},
                                    props:{
                                        value: record.batch,
                                    },
                                    on:{
                                        blur: (data: any) => {
                                            record.batch = data.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    }
                ]
            },
            {
                title: "结存和结存状态",
                align: "center",
                children:[
                    {
                        title: "过筛(kg)",
                        dataIndex: "screen",
                        key: "screen",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input",
                                {
                                    style:{width:"100%"},
                                    props:{
                                        value: record.screen,
                                    },
                                    on:{
                                        blur: (data: any) => {
                                            record.screen = data.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "总混一(kg)",
                        dataIndex: "stockNumSys",// TODO 后端说临时改成stockNumSys 备用zhOne
                        key: "stockNumSys1",//zhOne
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input",
                                {
                                    style:{width:"100%"},
                                    props:{
                                        value: record.stockNumSys,
                                    },
                                    on:{
                                        blur: (data: any) => {
                                            record.stockNumSys = data.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                           )
                        }
                    },
                    {
                        title: "总混一(质量状态)",
                        dataIndex: "qualityStatusOne",
                        key: "qualityStatusOne",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-select",
                                {
                                    style:{width:"100%"},
                                    props:{
                                        value: record.qualityStatusOne,
                                        options:[
                                            {
                                                value:"可用",
                                                label:"可用"
                                            },
                                            {
                                                value:"不可用",
                                                label:"不可用"
                                            },
                                        ]
                                    },
                                    on:{
                                        change: (value: any) => {
                                            record.qualityStatusOne = value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "颗粒批号",
                        dataIndex: "keLiBatch",
                        key: "keLiBatch",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input",
                                {
                                    style:{width:"100%"},
                                    props:{
                                        value: record.keLiBatch,
                                    },
                                    on:{
                                        blur: (data: any) => {
                                            record.keLiBatch = data.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "颗粒结存量(kg)",
                        dataIndex: "stockNumSys",
                        key: "stockNumSys",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input",
                                {
                                    style:{width:"100%"},
                                    props:{
                                        value: record.stockNumSys,
                                    },
                                    on:{
                                        blur: (data: any) => {
                                            record.stockNumSys = data.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                           )
                        }
                    },
                    {
                        title: "质量状态（颗粒）",
                        dataIndex: "qualityStatusKeLi",
                        key: "qualityStatusKeLi",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-select",
                                {
                                    style:{width:"100%"},
                                    props:{
                                        value: record.qualityStatusKeLi,
                                        options:[
                                            {
                                                value:"可用",
                                                label:"可用"
                                            },
                                            {
                                                value:"不可用",
                                                label:"不可用"
                                            },
                                        ]
                                    },
                                    on:{
                                        change: (value: any) => {
                                            record.qualityStatusKeLi = value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    }
                ]
            },
            {
                title: "过筛提取物",
                align: "center",
                children:[
                    {
                        title: "过筛粉碎入库",
                        align: "center",
                        children:[
                            {
                                title: "日期",
                                dataIndex: "screenInTime",
                                key: "screenInTime",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-date-picker",
                                        {
                                            props:{
                                                value: record.screenInTime,
                                                locale: this.locale,
                                            },
                                            on:{
                                                change: (value: any) => {
                                                    record.screenInTime = value
                                                    this.updateByTable(record)
                                                }
                                            }
                                       },
                                    )
                                }
                            },
                            {
                                title: "kg/件",
                                dataIndex: "screenInStorage",
                                key: "screenInStorage",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input",
                                        {
                                            style:{width:"100%"},
                                            props:{
                                                value: record.screenInStorage,
                                            },
                                            on:{
                                                blur: (data: any) => {
                                                    record.screenInStorage = data.target.value
                                                   this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            },
                            {
                                title: "件数",
                                dataIndex: "screenInStorageNum",
                                key: "screenInStorageNum",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input",
                                        {
                                            style:{width:"100%"},
                                            props:{
                                                value: record.screenInStorageNum,
                                            },
                                            on:{
                                                blur: (data: any) => {
                                                    record.screenInStorageNum = data.target.value
                                                    this.updateByTable(record)
                                                }
                                           }
                                        }
                                    )
                                }
                            },
                            {
                                title: "零件",
                                dataIndex: "screenInStorageSpare",
                                key: "screenInStorageSpare",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input",
                                        {
                                            style:{width:"100%"},
                                            props:{
                                                value: record.screenInStorageSpare,
                                            },
                                            on:{
                                                blur: (data: any) => {
                                                    record.screenInStorageSpare = data.target.value
                                                    this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            },
                            {
                                title: "重量(kg)",
                                dataIndex: "screenInStorageWeight",
                                key: "screenInStorageWeight",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input",
                                        {
                                            style:{width:"100%"},
                                            props:{
                                                value: record.screenInStorageWeight,
                                            },
                                            on:{
                                                blur: (data: any) => {
                                                    record.screenInStorageWeight = data.target.value
                                                    this.updateByTable(record)
                                                }
                                           }
                                        }
                                    )
                                }
                            },
                        ]
                    },
                    {
                        title: "出库",
                        align: "center",
                        children:[
                            {
                                title: "领用日期",
                                dataIndex: "outTime",
                                key: "outTime",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-date-picker",
                                        {
                                            props:{
                                                value: record.outTime,
                                                valueFormat: "YYYY-MM-DD",
                                                locale: this.locale,
                                            },
                                            on:{
                                                change: (date: any) => {
                                                    record.outTime = date
                                                    this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            },
                            {
                                title: "混合领(kg)",
                                dataIndex: "outKg",
                                key: "outKg",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input",
                                        {
                                            style:{width:"100%"},
                                            props:{
                                                value: record.outKg,
                                            },
                                            on:{
                                                blur: (data: any) => {
                                                    record.outKg = data.target.value
                                                    this.updateByTable(record)
                                                }
                                          }
                                        }
                                    )
                                }
                            },
                            {
                                title: "其他领(kg)",
                                dataIndex: "outOther",
                                key: "outOther",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input",
                                        {
                                            style:{width:"100%"},
                                            props:{
                                                value: record.outOther,
                                            },
                                            on:{
                                                blur: (data: any) => {
                                                    record.outOther = data.target.value
                                                    this.updateByTable(record)
                                                }
                                           }
                                        }
                                    )
                                },
                            },
                        ]
                    },
                    {
                        title: "结存(过筛)kg",
                        dataIndex: "balance",
                        key: "balance",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input",
                                {
                                    style:{width:"100%"},
                                    props:{
                                        value: record.balance,
                                    },
                                    on:{
                                        blur: (data: any) => {
                                            record.balance = data.target.value
                                            this.updateByTable(record)
                                       }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "过筛后粉位置",
                        dataIndex: "backPosition",
                        key: "backPosition",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input",
                                {
                                    style:{width:"100%"},
                                    props:{
                                        value: record.backPosition,
                                    },
                                    on:{
                                        blur: (data: any) => {
                                            record.backPosition = data.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        },
                    },
                    {
                        title: "复检期",
                        dataIndex: "recheckTime",
                        key: "recheckTime",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-date-picker",
                                {
                                    props:{
                                        value: record.recheckTime,
                                        valueFormat: "YYYY-MM-DD",
                                        locale: this.locale,
                                    },
                                    on:{
                                        change: (date: any) => {
                                            record.recheckTime = date
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                           )
                        },
                    },
                    {
                        title: "备注1",
                        dataIndex: "gsRemarkOne",
                        key: "gsRemarkOne",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input",
                                {
                                    style:{width:"100%"},
                                    props:{
                                        value: record.gsRemarkOne,
                                    },
                                    on:{
                                        blur: (data: any) => {
                                            record.gsRemarkOne = data.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                ]
            },
            {
                title: "总混一",
                align: "center",
                children:[
                    {
                        title: "入库",
                        align: "center",
                        children:[
                            {
                                title: "日期",
                                dataIndex: "storageInTime",
                                key: "storageInTime",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-date-picker",
                                        {
                                            props:{
                                                value: record.storageInTime,
                                                valueFormat: "YYYY-MM-DD",
                                                locale: this.locale,
                                            },
                                            on:{
                                                change: (date: any) => {
                                                    record.storageInTime = date
                                                    this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            },
                            {
                                title: "批号",
                                dataIndex: "storageInBatch",
                                key: "storageInBatch",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input",
                                        {
                                            style:{width:"100%"},
                                            props:{
                                                value: record.storageInBatch,
                                            },
                                            on:{
                                                blur: (data: any) => {
                                                    record.storageInBatch = data.target.value
                                                   this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            },
                            {
                                title: "重量(kg)",
                                dataIndex: "storageInWeight",
                                key: "storageInWeight",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input-number",
                                        {
                                            props:{
                                                value: record.storageInWeight,
                                            },
                                            on:{
                                                blur: (e: any) => {
                                                    record.storageInWeight = e.target.value
                                                    this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            },
                        ]
                    },
                    {
                        title: "出库",
                        align: "center",
                        children:[
                            {
                                title: "日期",
                                dataIndex: "storageOutTime",
                                key: "storageOutTime",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-date-picker",
                                        {
                                            props:{
                                                value: record.storageOutTime,
                                                valueFormat: "YYYY-MM-DD",
                                                locale: this.locale,
                                            },
                                            on:{
                                                change: (date: any) => {
                                                    record.storageOutTime = date
                                                    this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            },
                            {
                                title: "重量(kg)",
                                dataIndex: "storageOutWeight",
                                key: "storageOutWeight",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input-number",
                                        {
                                            props:{
                                                value: record.storageOutWeight,
                                            },
                                            on:{
                                                blur: (e: any) => {
                                                    record.storageOutWeight = e.target.value
                                                    this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            },
                        ]
                    },
                    {
                        title: "混一结存(kg)",
                        dataIndex: "balanceOne",
                        key: "balanceOne",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input-number",
                                {
                                    props:{
                                        value: record.balanceOne,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.balanceOne = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                               }
                            )
                        }
                    },
                    {
                        title: "总混一后位置",
                        dataIndex: "oneBackPosition",
                        key: "oneBackPosition",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.oneBackPosition,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.oneBackPosition = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "失效期",
                        dataIndex: "invalidTime",
                        key: "invalidTime",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-date-picker",
                                {
                                    props:{
                                        value: record.invalidTime,
                                        valueFormat: "YYYY-MM-DD",
                                        locale: this.locale,
                                    },
                                    on:{
                                        change: (date: any) => {
                                            record.invalidTime = date
                                            this.updateByTable(record)
                                        }
                                   }
                                }
                            )
                        }
                    },
                    {
                        title: "GMP报告数",
                        dataIndex: "gmpReportNum",
                        key: "gmpReportNum",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input-number",
                                {
                                    props:{
                                        value: record.gmpReportNum,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.gmpReportNum = e.target.value
                                            this.updateByTable(record)
                                        }
                                   }
                                }
                            )
                        }
                    },
                    {
                        title: "备注1",
                        dataIndex: "zhyRemarkOne",
                        key: "zhyRemarkOne",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.zhyRemarkOne,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.zhyRemarkOne = e.target.value
                                            this.updateByTable(record)
                                        }
                                   }
                                }
                            )
                        }
                    },
                ]
            },
            {
                title: "日期(制粒产出)",
                dataIndex: "zlProdTime",
                key: "zlProdTime",
                align: "center",
                customRender: (text: any, record: any, index: any) => {
                    return h(
                        "a-date-picker",
                        {
                            props:{
                                value: record.zlProdTime,
                                valueFormat: "YYYY-MM-DD",
                                locale: this.locale,
                            },
                            on:{
                                change: (date: any) => {
                                    record.zlProdTime = date
                                    this.updateByTable(record)
                                }
                           }
                        }
                    )
                }
            },
            {
                title: "颗粒批号",
                dataIndex: "zhyklBatch",
                key: "zhyklBatch",
                align: "center",
                customRender: (text: any, record: any, index: any) => {
                    return h(
                        "a-input",
                        {
                            props:{
                                value: record.zhyklBatch,
                            },
                            on:{
                                blur: (e: any) => {
                                    record.zhyklBatch = e.target.value
                                    this.updateByTable(record)
                                }
                           }
                        }
                    )
                }
            },
            {
                title: "复检期",
                dataIndex: "klProdTime",
                key: "klProdTime",
                align: "center",
                customRender: (text: any, record: any, index: any) => {
                    return h(
                        "a-date-picker",
                        {
                            props:{
                                value: record.klProdTime,
                                valueFormat: "YYYY-MM-DD",
                                locale: this.locale,
                            },
                            on:{
                                change: (date: any) => {
                                    record.klProdTime = date
                                    this.updateByTable(record)
                                }
                           }
                       }
                    )
                }
            },
            {
                title: "类别/省份",
                dataIndex: "klProdProvince",
                key: "klProdProvince",
                align: "center",
                customRender: (text: any, record: any, index: any) => {
                    return h(
                        "a-input",
                        {
                            props:{
                                value: record.klProdProvince,
                            },
                            on:{
                                blur: (e: any) => {
                                    record.klProdProvince = e.target.value
                                    this.updateByTable(record)
                                }
                           }
                        }
                    )
                }
            },
            {
                title: "kg/件",
                dataIndex: "klProdKg",
                key: "klProdKg",
                align: "center",
                customRender: (text: any, record: any, index: any) => {
                    return h(
                        "a-input",
                        {
                            props:{
                                value: record.klProdKg,
                            },
                            on:{
                                blur: (e: any) => {
                                    record.klProdKg = e.target.value
                                    this.updateByTable(record)
                                }
                           }
                        }
                    )
                }
            },
            {
                title: "件数",
                dataIndex: "klProdNum",
                key: "klProdNum",
                align: "center",
                customRender: (text: any, record: any, index: any) => {
                    return h(
                        "a-input",
                        {
                            props:{
                                value: record.klProdNum,
                            },
                            on:{
                                blur: (e: any) => {
                                    record.klProdNum = e.target.value
                                    this.updateByTable(record)
                                }
                           }
                        }
                    )
                }
            },
            {
                title: "零件(kg)",
                dataIndex: "klProdSpareKg",
                key: "klProdSpareKg",
                align: "center",
                customRender: (text: any, record: any, index: any) => {
                    return h(
                        "a-input",
                        {
                            props:{
                                value: record.klProdSpareKg,
                            },
                            on:{
                                blur: (e: any) => {
                                    record.klProdSpareKg = e.target.value
                                    this.updateByTable(record)
                                }
                           }
                        }
                    )
                }
            },
            {
                title: "总重量(kg)",
                dataIndex: "klProdTotalWeight",
                key: "klProdTotalWeight",
                align: "center",
                customRender: (text: any, record: any, index: any) => {
                    return h(
                        "a-input",
                        {
                            props:{
                                value: record.klProdTotalWeight,
                            },
                            on:{
                                blur: (e: any) => {
                                    record.klProdTotalWeight = e.target.value
                                    this.updateByTable(record)
                                }
                           }
                        }
                    )
                }
            },
            {
                title: "U8入账",
                dataIndex: "klProdU8",
                key: "klProdU8",
                align: "center",
                customRender: (text: any, record: any, index: any) => {
                    return h(
                        "a-input",
                        {
                            props:{
                                value: record.klProdU8,
                            },
                            on:{
                                blur: (e: any) => {
                                    record.klProdU8 = e.target.value
                                    this.updateByTable(record)
                                }
                           }
                        }
                    )
                }
            },
            {
                title: "GMP报告数",
                dataIndex: "klProdGmpReportNum",
                key: "klProdGmpReportNum",
                align: "center",
                customRender: (text: any, record: any, index: any) => {
                    return h(
                        "a-input",
                        {
                            props:{
                                value: record.klProdGmpReportNum,
                            },
                            on:{
                                blur: (e: any) => {
                                    record.klProdGmpReportNum = e.target.value
                                    this.updateByTable(record)
                                }
                           }
                        }
                    )
                }
            },
            {
                title: "挥发油",
                align: "center",
                children:[
                    {
                        title: "日期",
                        dataIndex: "oilDate",
                        key: "oilDate",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-date-picker",
                                {
                                    props:{
                                        value: record.oilDate,
                                        locale: this.locale,
                                    },
                                    on:{
                                        change: (data: any) => {
                                            record.oilDate = data
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        },
                    },
                    {
                        title: "工序总混/过筛",
                        dataIndex: "oilTech",
                        key: "oilTech",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.oilTech,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.oilTech = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        },
                    },
                    {
                        title: "出库",
                        dataIndex: "oilOut",
                        key:"oilOut",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.oilOut,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.oilOut = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "入库",
                        dataIndex: "oilIn",
                        key:"oilIn",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.oilIn,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.oilIn = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                ]
            },
            {
                title: "验证出库",
                align: "center",
                children:[
                    {
                        title: "分装C60/C80",
                        align: "center",
                        children:[
                            {
                                title: "验证",
                                align: "center",
                                children:[
                                    {
                                        title: "出库日期",
                                        dataIndex: "c68OutDate",
                                        key: "c68OutDate",
                                        align: "center",
                                        customRender: (text: any, record: any, index: any) => {
                                            return h(
                                                "a-date-picker",
                                                {
                                                    props:{
                                                        value: record.c68OutDate,
                                                        locale: this.locale,
                                                    },
                                                    on:{
                                                        change: (data: any) => {
                                                            record.c68OutDate = data
                                                            this.updateByTable(record)
                                                        }
                                                    }
                                                }
                                            )
                                        }
                                    },
                                    {
                                        title: "重量kg",
                                        dataIndex: "c68Weight",
                                        key: "c68Weight",
                                        align: "center",
                                        customRender: (text: any, record: any, index: any) => {
                                            return h(
                                                "a-input-number",
                                                {
                                                    props:{
                                                        value: record.c68Weight,
                                                    },
                                                    on:{
                                                        blur: (e: any) => {
                                                            record.c68Weight = e.target.value
                                                            this.updateByTable(record)
                                                        }
                                                    }
                                                }
                                           )
                                        }
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        title: "分装C70/C90",
                        align: "center",
                        children:[
                            {
                                title: "验证",
                                align: "center",
                                children:[
                                    {
                                        title: "出库日期",
                                        dataIndex: "c79OutDate",
                                        key: "c79OutDate",
                                        align: "center",
                                        customRender: (text: any, record: any, index: any) => {
                                            return h(
                                                "a-date-picker",
                                                {
                                                    props:{
                                                        value: record.c79OutDate,
                                                        locale: this.locale,
                                                    },
                                                    on:{
                                                        change: (data: any) => {
                                                            record.c79OutDate = data
                                                            this.updateByTable(record)
                                                        }
                                                    }
                                                }
                                            )
                                        }
                                    },
                                    {
                                        title: "重量kg",
                                        dataIndex: "c79Weight",
                                        key: "c79Weight",
                                        align: "center",
                                        customRender: (text: any, record: any, index: any) => {
                                            return h(
                                                "a-input-number",
                                                {
                                                    props:{
                                                        value: record.c79Weight,
                                                    },
                                                    on:{
                                                        blur: (e: any) => {
                                                            record.c79Weight = e.target.value
                                                            this.updateByTable(record)
                                                        }
                                                    }
                                                }
                                            )
                                        }
                                    }
                                ]
                            }
                        ]
                    },
                ]
            },
            {
                title: "大生产出库",
                align: "center",
                children:[
                    {
                        title: "分装C60",
                        align: "center",
                        children:[
                            {
                                title: "分装C60日期",
                                dataIndex: "c6Date",
                                key: "c6Date",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-date-picker",
                                        {
                                            props:{
                                                value: record.c6Date,
                                                locale: this.locale,
                                            },
                                            on:{
                                                change: (data: any) => {
                                                    record.c6Date = data
                                                    this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            },
                            {
                                title: "成品批号",
                                dataIndex: "c6Batch",
                                key: "c6Batch",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input",
                                        {
                                            props:{
                                                value: record.c6Batch,
                                            },
                                            on:{
                                                blur: (e: any) => {
                                                    record.c6Batch = e.target.value
                                                    this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            },
                            {
                                title: "重量kg",
                                dataIndex: "c6Kg",
                                key: "c6Kg",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input-number",
                                        {
                                            props:{
                                                value: record.c6Kg,
                                            },
                                            on:{
                                                blur: (e: any) => {
                                                    record.c6Kg = e.target.value
                                                    this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            }
                        ]
                    },
                    {
                        title: "分装C70",
                        align: "center",
                        children:[
                            {
                                title: "分装C70日期",
                                dataIndex: "c7Date",
                                key: "c7Date",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-date-picker",
                                        {
                                            props:{
                                                value: record.c7Date,
                                                locale: this.locale,
                                            },
                                            on:{
                                                change: (data: any) => {
                                                    record.c7Date = data
                                                    this.updateByTable(record)
                                                }
                                            }
                                       }
                                    )
                                }
                            },
                            {
                                title: "成品批号",
                                dataIndex: "c7Batch",
                                key: "c7Batch",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input",
                                        {
                                            props:{
                                                value: record.c7Batch,
                                            },
                                            on:{
                                                blur: (e: any) => {
                                                    record.c7Batch = e.target.value
                                                    this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            },
                            {
                                title: "重量kg",
                                dataIndex: "c7Kg",
                                key: "c7Kg",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input-number",
                                        {
                                            props:{
                                                value: record.c7Kg,
                                            },
                                            on:{
                                                blur: (e: any) => {
                                                    record.c7Kg = e.target.value
                                                    this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            }
                        ]
                    },
                    {
                        title: "分装C80",
                        align: "center",
                        children:[
                            {
                                title: "分装C80日期",
                                dataIndex: "c8Date",
                                key: "c8Date",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-date-picker",
                                        {
                                            props:{
                                                value: record.c8Date,
                                                locale: this.locale,
                                            },
                                            on:{
                                                change: (data: any) => {
                                                    record.c8Date = data
                                                    this.updateByTable(record)
                                                }
                                            }
                                      }
                                    )
                                }
                            },
                            {
                                title: "成品批号",
                                dataIndex: "c8Batch",
                                key: "c8Batch",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input",
                                        {
                                            props:{
                                                value: record.c8Batch,
                                            },
                                            on:{
                                                blur: (e: any) => {
                                                    record.c8Batch = e.target.value
                                                    this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            },
                            {
                                title: "重量kg",
                                dataIndex: "c8Kg",
                                key: "c8Kg",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input-number",
                                        {
                                            props:{
                                                value: record.c8Kg,
                                            },
                                            on:{
                                                blur: (e: any) => {
                                                    record.c8Kg = e.target.value
                                                    this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            }
                        ]
                    },
                    {
                        title: "分装C90",
                        align: "center",
                        children:[
                            {
                                title: "分装C90日期",
                                dataIndex: "c9Date",
                                key: "c9Date",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-date-picker",
                                        {
                                            props:{
                                                value: record.c9Date,
                                                locale: this.locale,
                                            },
                                            on:{
                                                change: (data: any) => {
                                                    record.c9Date = data
                                                    this.updateByTable(record)
                                                }
                                            }
                                     }
                                    )
                                }
                            },
                            {
                                title: "成品批号",
                                dataIndex: "c9Batch",
                                key: "c9Batch",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input",
                                        {
                                            props:{
                                                value: record.c9Batch,
                                            },
                                            on:{
                                                blur: (e: any) => {
                                                    record.c9Batch = e.target.value
                                                    this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            },
                            {
                                title: "重量kg",
                                dataIndex: "c9Kg",
                                key: "c9Kg",
                                align: "center",
                                customRender: (text: any, record: any, index: any) => {
                                    return h(
                                        "a-input-number",
                                        {
                                            props:{
                                                value: record.c9Kg,
                                            },
                                            on:{
                                                blur: (e: any) => {
                                                    record.c9Kg = e.target.value
                                                    this.updateByTable(record)
                                                }
                                            }
                                        }
                                    )
                                }
                            }
                        ]
                    },

                ]
            },
            {
                title: "其他出库",
                align: "center",
                children:[
                    {
                        title: "其他出库日期",
                        dataIndex: "otherOutDate",
                        key: "otherOutDate",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-date-picker",
                                {
                                    props:{
                                        value: record.otherOutDate,
                                        locale: this.locale,
                                    },
                                    on:{
                                        change: (data: any) => {
                                            record.otherOutDate = data
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "其他领",
                        dataIndex: "otherGet",
                        key: "otherGet",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input-number",
                                {
                                    props:{
                                        value: record.otherGet,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.otherGet = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                ]
            },
            {
                title: "颗粒结存",
                dataIndex:"klBalance",
                key:"klBalance",
                align: "center",
                customRender: (text: any, record: any, index: any) => {
                    return h(
                        "a-input-number",
                        {
                            props:{
                                value: record.klBalance,
                            },
                            on:{
                                blur: (e: any) => {
                                    record.klBalance = e.target.value
                                    this.updateByTable(record)
                                }
                            }
                        }
                    )
                }
            },
            {
                title: "颗粒存放位置",
                dataIndex:"klPosition",
                key:"klPosition",
                align: "center",
                customRender: (text: any, record: any, index: any) => {
                    return h(
                        "a-input",
                        {
                            props:{
                                value: record.klPosition,
                            },
                            on:{
                                blur: (e: any) => {
                                    record.klPosition = e.target.value
                                    this.updateByTable(record)
                                }
                            }
                        }
                    )
                }
            },
            {
                title: "FS状态",
                dataIndex:"fsState",
                key:"fsState",
                align: "center",
                customRender: (text: any, record: any, index: any) => {
                    return h(
                        "a-input",
                        {
                            props:{
                                value: record.fsState,
                            },
                            on:{
                                blur: (e: any) => {
                                    record.fsState = e.target.value
                                    this.updateByTable(record)
                                }
                            }
                        }
                    )
                }
            },
            {
                title: "备注",
                align: "center",
                children: [
                    {
                        title: "备注1",
                        dataIndex: "remarkOne",
                        key: "remarkOne",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.remarkOne,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.remarkOne = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                    {
                        title: "备注2",
                        dataIndex: "remarkTwo",
                        key: "remarkTwo",
                        align: "center",
                        customRender: (text: any, record: any, index: any) => {
                            return h(
                                "a-input",
                                {
                                    props:{
                                        value: record.remarkTwo,
                                    },
                                    on:{
                                        blur: (e: any) => {
                                            record.remarkTwo = e.target.value
                                            this.updateByTable(record)
                                        }
                                    }
                                }
                            )
                        }
                    },
                ]
            },
            {
                align: "center",
                dataIndex: "action",
                key: "action",
                title: "操作",
                width: 260,
                customRender: (text: any, record: any) => {
                    const editBtn = h(
                        "a-button",
                        {
                            style: { marginRight: "5px" },
                            props: { icon: "edit", type: "primary", size: "small" },
                            on: { click: () => this.edit(record) },
                        },
                        "编辑"
                    );
                    const delBtn = h(
                        "a-button",
                        {
                            style: { marginRight: "5px" },
                            props: { icon: "edit", type: "danger", size: "small" },
                            on: { click: () => this.del(record) },
                        },
                        "删除"
                    );
                    const btn: any[] = [];
                    btn.push(editBtn);
                    // btn.push(delBtn);
                    return h("div", btn);
                },
            },
        ],
        dataSource: [],
        pagination: {
            pageSize: 10,
            current: 1,
            total: 0,
            showTotal: (total: number) => `共${total}条`,
            onChange: this.pageChange,
        }
    }
    locale:any =  locale;
    pageChange(page: number, pageSize: number) {
        console.log(page, pageSize);
        this.getTableData(this.type)
    }
    formShow = false
    add(){
        this.formShow = true
    }
    del(record: any){
    }
    async updateByTable(record:any){
        try {
            this.tableOption.loading = true
            const result = await nextApi.productStorageUpdate(record)
            this.$message.success(result.msg)
            await this.getTableData(this.type)
        }finally {
            this.tableOption.loading = false
        }
    }
    formEditId = ''
    formData:any = {}
    edit(records:any){
        this.formShow = true
        this.formEditId = records.id
        this.formData = records
    }
    formClose(){
        this.formShow = false
        this.formEditId = ''
        this.getTableData(this.type)
    }
    type = '提取物'
    async getTableData(v){
        try{
            this.type = v
            this.tableOption.loading = true
            let params = {
                pageSize: this.tableOption.pagination.pageSize,
                pageNum: this.tableOption.pagination.current,
                materialType:this.type
            }
            const res = await nextApi.productStorageList(params)
            console.log(res)
            this.tableOption.dataSource = res.data?.records || []
            this.tableOption.pagination.total = res.data?.total || 0
        }finally {
            this.tableOption.loading = false
        }
    }
    beforeMount() {
        this.addWidth(this.tableOption.tableColumns)
    }
    addWidth(arr){
        arr.forEach(item=>{
            if(item.children){
                this.addWidth(item.children)
            }else{
                item.width = 150
            }
            if(item.title == '操作')item.width = 260
            if(item.title == '操作')item.fixed = 'right'
        })
    }
    mounted() {
        this.getTableData(this.type)

    }
    downloadTemplate(){
        this.tableOption.loading = true
        nextApi.getProductStorageImportTemplate('','',(res) => {
            const blob = new Blob([res.data], {
                type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                // type: "application/vnd.ms-excel",
            });
            downLoadFile(blob, "库存表导入模板");
            this.tableOption.loading = false;
        });
    }
    beforeUpload(file: any) {
        let formData = new FormData();
        formData.append("file", file);
        this.uploadTemplate(formData);
        return false;
    }
    async uploadTemplate(formData: any) {
        this.tableOption.loading = true;
        try {
            const res = await nextApi.importProductStorage(formData);
            this.$message.success(res.msg);
        } finally {
            this.tableOption.loading = false;
        }
    }
}
</script>
<style scoped lang="scss">

</style>
